package com.zfdang.touchhelper.tool;

import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.content.Context;
import android.os.Build;

import androidx.annotation.NonNull;
import androidx.core.app.NotificationCompat;

import com.aivin.adovertool.R;

/**
 * @author Aivin
 * created on 2023/11/10
 * des:
 */
public class LyNotifactionTool {

    public static LyNotifactionTool getInstance() {
        return LyNotifactionTool.SingletonFactory.INSTANCE;
    }

    private static class SingletonFactory {
        private static final LyNotifactionTool INSTANCE = new LyNotifactionTool();
    }

    private  Context context;
    private final  String CHANNELID = "channel_01";

    /**
     * 初始化工具类
     */
    public  void init(@NonNull final Context context) {
        this.context = context.getApplicationContext();
        initNotificationChannel();
    }


    private  void initNotificationChannel() {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            NotificationManager notificationManager =
                    (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
            CharSequence name = "clock";
            NotificationChannel notificationChannel =
                    new NotificationChannel(CHANNELID, name, NotificationManager.IMPORTANCE_DEFAULT);
            //在notificationManager中创建通知渠道
            notificationManager.createNotificationChannel(notificationChannel);
        }
    }


    public  void showNotification(int notificationId, String clockTime, String tips) {
        NotificationManager notificationManager =
                (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
        //设置图片,通知标题,发送时间,提示方式等属性
        Notification notification = new NotificationCompat.Builder(context, CHANNELID)
                //标题
                .setContentTitle("测试内容 " + clockTime)
                //内容
                .setContentText(tips)
                //收到信息后状态栏显示的文字信息
                //.setTicker("收到叶Android发送过来的信息~")
                //设置通知时间
                .setWhen(System.currentTimeMillis())
                //设置小图标
                .setSmallIcon(R.drawable.ic_touch_helper_icon)
                //.setLargeIcon(BitmapFactory.decodeResource(getResources(),R.drawable.ic_launcher_background))                     //设置大图标
                //.setAutoCancel(true)                           //设置点击后取消Notification
                //.setContentIntent(pit)                         //设置PendingIntent
                .build();
        notificationManager.notify(notificationId, notification);
        LyLog.showLog("tips==="+tips);
    }
}
